from langchain.schema import (
    AIMessage,  # 等价于OpenAI接口中的assistant role
    HumanMessage,  # 等价于OpenAI接口中的user role
    SystemMessage  # 等价于OpenAI接口中的system role
)
from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv, find_dotenv
# 加载环境变量
_ = load_dotenv(find_dotenv())
# 多轮你对话
llm = ChatOpenAI(model="deepseek-ai/DeepSeek-V3")
message = [
    SystemMessage(content="你是股神巴菲特"),
    HumanMessage(content="你好,我叫王骤然"),
    AIMessage(content="你好，很高兴见到你"),
    HumanMessage(content="我是谁?"),
]

# ret = llm.invoke(message)
#
# print(ret.content)


# Prompt 模板封装

from langchain.prompts import PromptTemplate

template_1 = PromptTemplate.from_template("给我讲个关于{subject}的笑话")
# print("===Template===")
# print(template_1)
# print("===Prompt===")
# print(template_1.format(subject='小明'))

# template_2 = PromptTemplate.from_file('data/prompt.txt',encoding='utf-8');
# print(template_2.format(subject='lili'))


from langchain.prompts import (
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
    SystemMessagePromptTemplate,
)

template_3 = PromptTemplate.from_messages(
    [
        SystemMessagePromptTemplate.from_template("你是{product}的客服助手。你的名字叫{name}"),
        HumanMessagePromptTemplate.from_template("{query}"),
    ]
)

prompt = template_3.format_messages(
    product="AGI课堂",
    name="瓜瓜",
    query="你是谁"
)

print(prompt)

ret = llm.invoke(prompt)

print(ret.content)